﻿using DevelopTool.Forms.BaseForms;
using Sunny.UI;
using System;

namespace DevelopTool.Forms.EncodOrEncrypForms
{
    /// <summary>
    /// Base64文本编码/解码
    /// </summary>
    public partial class Base64TextForm : BaseUIPage
    {

        public Base64TextForm()
        {
            InitializeComponent();
        }

        private void Base64TextForm_Load(object sender, EventArgs e)
        {
        }



        /// <summary>
        /// 编码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEncode_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.codeEditorIn.ContentText))
                {
                    this.ShowWarningNotifier("请输入需要编码的文本");
                    return;
                }

                this.codeEditorOut.ContentText = this.codeEditorIn.ContentText.Base64Encode();
                this.ShowWarningTip(this.btnEncode, "已编码");
            }
            catch (Exception ex)
            {
                this.ShowErrorDialog(ex.Message);
            }

        }

        /// <summary>
        /// 解码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDecode_Click(object sender, EventArgs e)
        {
            try
            {

                if (string.IsNullOrEmpty(this.codeEditorIn.ContentText))
                {
                    this.ShowWarningNotifier("请输入需要解码的文本");
                    return;
                }

                codeEditorOut.ContentText = codeEditorIn.ContentText.Base64Decode();
                this.ShowWarningTip(this.btnDecode, "已解码");
            }
            catch (Exception ex)
            {
                this.ShowErrorDialog(ex.Message);
            }

        }


    }
}
